package yunhe.servlet;

import org.json.JSONArray;
import org.json.JSONObject;
import yunhe.biz.StockMgrBiz;
import yunhe.biz.impl.StockMgrBizImpl;
import yunhe.entity.Inventory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2017/6/19.
 */
@WebServlet(name = "GetDefaultStoInvServlet",urlPatterns = "/GetDefaultStoInvServlet")
public class GetDefaultStoInvServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String stoId=request.getParameter("stoId");
        StockMgrBiz sb=new StockMgrBizImpl();
        JSONArray ja=new JSONArray();
        List<Inventory> li;
        if(stoId.equals("default")){
            li=sb.searchInv();
        }
        else{
           li=sb.searchInvBySto(stoId);
        }
        for (Inventory i:li){
            JSONObject jo=new JSONObject(i);
            ja.put(jo);
        }

        System.out.println(ja.toString());
        response.getWriter().print(ja.toString());
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
